class Solution {
public:
    bool flag[7];
    vector<int> path;
    vector<vector<int>> v;
    vector<vector<int>> permute(vector<int>& nums) {
        dfs(nums);
        return v;
    }
    void dfs(vector<int>& nums)
    {
        if (path.size() == nums.size())
        {
            v.push_back(path);
            return;
        }
        for (int i = 0; i < nums.size(); i++)
        {
            if (flag[i] == false)
            {
                path.push_back(nums[i]);
                flag[i] = true;
                dfs(nums);
                flag[i] = false;
                path.pop_back();
            }
        }
    }
};
class Solution {
public:
    vector<int> path;
    vector<vector<int>> v;
    vector<vector<int>> subsets(vector<int>& nums) {
        dfs(nums, 0);
        return v;
    }
    void dfs(vector<int>& nums, int i) {
        v.push_back(path);
        for (int x = i; x < nums.size(); x++) {
            path.push_back(nums[x]);
            dfs(nums, x + 1);
            path.pop_back();
        }
    }
};
class Solution {
public:
    int ret;
    vector<int> path;
    int subsetXORSum(vector<int>& nums) {
        dfs(nums, 0);
        return ret;
    }
    void dfs(vector<int>& nums, int i)
    {
        int count = 0;
        for (auto ch : path) count ^= ch;
        cout << count << " ";
        ret += count;
        for (int x = i; x < nums.size(); x++)
        {
            path.push_back(nums[x]);
            dfs(nums, x + 1);
            path.pop_back();
        }
    }
};
class Solution {
public:
    vector<string> v{ "",    " ",   "abc",  "def", "ghi",
                     "jkl", "mno", "pqrs", "tuv", "wxyz" };
    vector<string> num;
    string ptm;
    void Combinations(string digits, size_t x) {
        if (x == digits.size()) {
            num.push_back(ptm);
            return;
        }
        int y = digits[x] - '0';
        int size = v[y].size();
        for (size_t i = 0; i < size; i++) {
            ptm.push_back(v[y][i]);
            Combinations(digits, x + 1);
            ptm.pop_back();
        }
    }

    vector<string> letterCombinations(string digits) {
        if (digits.size() == 0) {
            return num;
        }
        Combinations(digits, 0);
        return num;
    }
};
